package com.person.yan.a01_retrofit.nat.impl;

import android.text.TextUtils;

import com.person.yan.a01_retrofit.bean.ResponseInfo;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by ywy on 2017-09-29.
 */

public abstract class SimpleCallBack implements Callback<ResponseInfo> {

    @Override
    public void onResponse(Call<ResponseInfo> call, Response<ResponseInfo> response) {
        String json = response.body().getData();
        if(!TextUtils.isEmpty(json)){
            returnData(1 , json);
        }else{
            returnError(2 , new RuntimeException("none json data"));
        }

    }

    public abstract void returnError(int i, Throwable e);

    public abstract void returnData(int i, String json);

    @Override
    public void onFailure(Call<ResponseInfo> call, Throwable t) {
        returnError(-1 , t);

    }
}
